package com.blb.zycommunity.controller;

import com.blb.zycommunity.entity.ResponseResult;
import com.blb.zycommunity.entity.SysUserPost;
import com.blb.zycommunity.service.ISysUserPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 用户与岗位关联表 前端控制器
 * </p>
 *
 * @author chenheng
 * @since 2023-11-20
 */
@RestController
@CrossOrigin
public class SysUserPostController {

    @Autowired
    private ISysUserPostService userPostService;

    @Transactional
    @PostMapping("/user-post/{userId}")
    public ResponseResult removeAndAddPostByUserId(@PathVariable Long userId, @RequestBody List<SysUserPost> userPost){
        userPostService.removePostByUserId(userId);
        userPostService.saveBatch(userPost);
        return ResponseResult.ok("ok");
    }

    @PostMapping("/user-posts")
    public ResponseResult addUserPots(@RequestBody List<SysUserPost> userPost){
        userPostService.saveBatch(userPost);
        return ResponseResult.ok("ok");
    }

}
